package refactorplugin.views;

import java.net.MalformedURLException;
import java.net.URL;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.ISharedImages;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.internal.UIPlugin;

import entity.TaskInfo;

import refactor.Activator;
import tasks.ITask;

public class TreeViewLabelProvider extends LabelProvider {

	public String getText(Object obj) {
		if (obj instanceof TreeLeaf)
			return obj.toString()+" Parameters: "+((TaskInfo)((TreeLeaf)obj).getElement()).getParameters();
		else
			return obj.toString();
	}
	public Image getImage(Object obj) {
		String imageKey = ISharedImages.IMG_OBJ_ELEMENT;
		URL installURL = Activator.getDefault().getDescriptor().getInstallURL();
		if (obj instanceof TreeComposite)
			if (((TreeComposite)obj).getName().contains(".java")) {
				try {
					ImageDescriptor iD = ImageDescriptor.createFromURL(new URL(installURL, "./icons/jfile.png"));
					return iD.createImage();
				} catch (MalformedURLException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
			else
				imageKey = ISharedImages.IMG_OBJ_FOLDER;
		if (obj instanceof TreeLeaf) {
			try {
				ImageDescriptor iD = ImageDescriptor.createFromURL(new URL(installURL, "./icons/task.png"));
				return iD.createImage();
			} catch (MalformedURLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		return PlatformUI.getWorkbench().getSharedImages().getImage(imageKey);
	}
}